/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.chl.mq._02_workqueue;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 *
 * @author 陈宏亮
 */
public class TaskQos {

    //队列名称  
    public final static String QUEUE_NAME = "chl_workqueue";

    public static void main(String[] args) throws Exception {
        //创建连接和频道  
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.2.221");
        factory.setUsername("guest");
        factory.setPassword("guest");
        try (Connection connection = factory.newConnection()) {
            Channel channel = connection.createChannel();
            
            //声明队列
            channel.queueDeclare(QUEUE_NAME, false, false, false, null);
            
            //发送10条消息，依次在消息后面附加1-10个点
            for (int i = 0; i < 10; i++) {
                String dots = "";
                for (int j = 0; j < (10 - i); j++) {
                    dots += ".";
                }
                String message = "人民币" + dots + dots.length();
                channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
                System.out.println("厂家 发送 '" + message + "'");
            }
            //关闭频道和资源
            channel.close();
        }
    }
}
